package cn.boat.router.broker.partition.strategy.impl;

import cn.boat.router.broker.partition.strategy.AbstractPartitionSelector;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * 随机分区选择器
 */
public class RandomPartitionSelector extends AbstractPartitionSelector {
    private Random random = new Random();
    @Override
    public List<Integer> getPartitionDistribution0(List<Integer> totalList, Integer num) {
        List<Integer> result = new LinkedList<>();
        while (num-- > 0) {
            Integer luckyDog = totalList.get(random.nextInt(totalList.size()));
            result.add(luckyDog);
            totalList.remove(luckyDog);
        }
        return result;
    }

    public static void main(String[] args) {
        RandomPartitionSelector r = new RandomPartitionSelector();
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.out.println(r.getPartitionDistribution0(list, 3));
    }
}
